package com.tobestronger.shouxiespringframework.aop;

import com.tobestronger.shouxiespringframework.util.ClassUtils;

/**
 * 被代理的目标对象 的包装类
 */
public class TargetSource {

    /**
     * 需要被代理的对象
     */
    private final Object target;

    public TargetSource(Object target) {
        this.target = target;
    }

    public Object getTarget(){
        return this.target;
    }

    public Class<?> getTargetClass(){
        Class<?> clazz = this.target.getClass();
        clazz = ClassUtils.isCglibProxyClass(clazz) ? clazz.getSuperclass() : clazz;
        return clazz;
    }


    public Class<?>[] getTargetClassInterfaces(){
        return getTargetClass().getInterfaces();
    }

}
